/**
 * Created with IntelliJ IDEA.
 * ClassName: ThrowTest
 * Package: PACKAGE_NAME
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-26
 * Time: 13:46
 */

public class ThrowTest {

    public static void main(String[] args) {
        Student student = new Student();

        try {
            student.regist(10);
            student.regist(-1);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(student);
    }

}


class Student{
    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                '}';
    }

    int id;

    public void regist(int id) throws Exception {

        if (id > 0){
            this.id = id;
        }else {
            //手动抛出异常
            //throw new RuntimeException("输入的ID非法");
            throw new BelowZeroException("输入的ID非法");
        }

    }


}